package com.fengze.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.fengze.business.vo.ClientLibraryVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fengze.common.annotation.Log;
import com.fengze.common.core.controller.BaseController;
import com.fengze.common.core.domain.AjaxResult;
import com.fengze.common.enums.BusinessType;
import com.fengze.business.domain.ClientLibrary;
import com.fengze.business.service.IClientLibraryService;
import com.fengze.common.utils.poi.ExcelUtil;
import com.fengze.common.core.page.TableDataInfo;

/**
 * 客户信息库Controller
 * 
 * @author lug
 * @date 2024-01-31
 */
@RestController
@RequestMapping("/counterpart/clientlibrary")
public class ClientLibraryController extends BaseController
{
    @Autowired
    private IClientLibraryService clientLibraryService;

    /**
     * 查询客户信息库列表
     */
    @PreAuthorize("@ss.hasPermi('counterpart:clientlibrary:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClientLibrary clientLibrary)
    {
        startPage();
//        List<ClientLibrary> list = clientLibraryService.selectClientLibraryList(clientLibrary);
        List<ClientLibraryVO> list = clientLibraryService.selectClientLibraryVOList(clientLibrary);
        return getDataTable(list);
    }

    /**
     * 导出客户信息库列表
     */
    @PreAuthorize("@ss.hasPermi('counterpart:clientlibrary:export')")
    @Log(title = "客户信息库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClientLibrary clientLibrary)
    {
        List<ClientLibrary> list = clientLibraryService.selectClientLibraryList(clientLibrary);
        ExcelUtil<ClientLibrary> util = new ExcelUtil<ClientLibrary>(ClientLibrary.class);
        util.exportExcel(response, list, "客户信息库数据");
    }

    /**
     * 获取客户信息库详细信息
     */
    @PreAuthorize("@ss.hasPermi('counterpart:clientlibrary:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(clientLibraryService.selectClientLibraryVOById(id));
    }

    /**
     * 新增客户信息库
     */
    @PreAuthorize("@ss.hasPermi('counterpart:clientlibrary:add')")
    @Log(title = "客户信息库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClientLibrary clientLibrary)
    {
        return toAjax(clientLibraryService.insertClientLibrary(clientLibrary));
    }

    /**
     * 修改客户信息库
     */
    @PreAuthorize("@ss.hasPermi('counterpart:clientlibrary:edit')")
    @Log(title = "客户信息库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClientLibrary clientLibrary)
    {
        return toAjax(clientLibraryService.updateClientLibrary(clientLibrary));
    }

    /**
     * 删除客户信息库
     */
    @PreAuthorize("@ss.hasPermi('counterpart:clientlibrary:remove')")
    @Log(title = "客户信息库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(clientLibraryService.deleteClientLibraryByIds(ids));
    }
}
